P = int(input())
now=[col for col in input().split("/") if col]

for i in range(0,P):
    line=input()
    if line=="":
        line=now[:]
    elif line[0]=="/":
        line=[col for col in line.split("/") if col]
    else:
        res=[col for col in line.split("/") if col]
        line=[]
        line.extend(now)
        line.extend(res)
    j=0
    length=len(line)
    while j<length:
        if line[j]==".":
            line.pop(j)
            length-=1
        elif line[j]=="..":
            line.pop(j)
            if j==0:
                length-=1
            else:
                j-=1
                line.pop(j)
                length-=2
        else:
            j+=1
    print("/"+"/".join(line))